package Top200;

import common.ListNode;

/**
 * @author zhangmin
 * @create 2022-02-26 15:10
 */
public class partition86 {
    public ListNode partition(ListNode head, int x) {
        ListNode head1=new ListNode(-1),head2=new ListNode(-1),p1=head1,p2=head2;
        while (head!=null){
            if (head.val<x){
                p1.next=new ListNode(head.val);
                p1=p1.next;
            }else {
                p2.next=new ListNode(head.val);
                p2=p2.next;
            }
            head=head.next;
        }
        p1.next=head2.next;
        return head1.next;
    }
}
